package com.czy.owner.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.ChainStoresModel;
import com.czy.owner.utils.glide.GlideUtils;
import com.czy.owner.widget.RoundImageView;

import java.util.List;

/**
 * Created by wangyang
 */
public class StorePopuMenuSelectAdapter extends BaseRecyclerAdapter<ChainStoresModel,StorePopuMenuSelectAdapter.StoreSelectHolder> {
    private String storeName;
    private Context ctx;
    public StorePopuMenuSelectAdapter(Context context, List<ChainStoresModel> data, String storeName) {
        super(context, data);
        this.ctx = context;
        this.storeName = storeName;
    }

    @Override
    public void onBindViewHolder(StoreSelectHolder holder, int position) {
        super.onBindViewHolder(holder, position);
            holder.bindData(data.get(position));
    }

    @Override
    public StoreSelectHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new StoreSelectHolder(layoutInflater.inflate(R.layout.item_store_popupwindow, parent, false));
    }

    public class StoreSelectHolder extends BaseRecyclerAdapter.ViewHolder{

        private RoundImageView img_store_head_portrait;
        private TextView tv_store_name;
        public StoreSelectHolder(View itemView) {
            super(itemView);
            img_store_head_portrait = (RoundImageView)itemView.findViewById(R.id.img_store_head_portrait);
            tv_store_name = (TextView)itemView.findViewById(R.id.tv_store_name);

        }
        public void bindData(ChainStoresModel model){
            GlideUtils.loadImage(ctx, model.getStroeLogo(), img_store_head_portrait, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            },R.mipmap.default_icon,R.mipmap.default_icon);
            tv_store_name.setText(model.getStoreName());
            if(storeName.equals(model.getStoreName())){
                tv_store_name.setTextColor(ctx.getResources().getColor(R.color.appThemeColor));
            }else {
                tv_store_name.setTextColor(ctx.getResources().getColor(R.color.tab_title_select_normal));
            }

        }
    }
}
